<?php
// digiboard by digitalboom.org
// http://www.digitalboom.org
//
// Information Technology program
// Sirindhorn International Institute of Technology
// Thammasat University, Rangsit Campus
// http://www.siit.tu.ac.th
//
// first created on: 2002 Xxx xx
// last modified on: 2002 May 12

function undo_htmlspecialchars($string) {
 $string = str_replace("&amp;", "&", $string);
 $string = str_replace("&quot;", "\"", $string);
 $string = str_replace("&lt;", "<", $string);
 $string = str_replace("&gt;", ">", $string);

 return $string;
}

function htmlencode($string) {
 $ret_string="";
 $len=strlen($string);
 for ($x=0;$x<$len;$x++) {
  $ord=ord(substr($string, $x, 1));
  $ret_string .= "&#$ord;";
 }
 return $ret_string;
}

function htmldecode($string) {
 $ret_string="";
 $arr   = explode("&#", $string);
 $count = count($arr);
 $x = 1; //ignore first element. it will be ""
 while ($x<$count) {
  $asc = ereg_replace("(.*);", "\\1", $arr[$x]);
  $chr = chr($asc);
  $ret_string .= $chr;
  $x++;
 }
 return $ret_string;
}

function my_nl2br($str) {
 $str = nl2br($str);
 return str_replace("><br>", ">", $str);
}

function bgcolor($color) {
 if($color!="") {
  return " bgcolor=\"".$color."\"";
 } else {
  return'';
 }
}

function initvar($varname, $value='') {
 global $$varname;
 if(!isset($$varname))
  $$varname=$value;
}

// GET And POST site variables
function AddGetVar($var, $value) {
 GLOBAL $GetVars;
 $var=urlencode($var);
 $value=urlencode($value);
 $GetVars.="&";
 $GetVars.="$var=$value";
}

function AddPostVar($var, $value) {
 GLOBAL $PostVars;
 $PostVars.="<input type=\"hidden\" name=\"$var\" value=\"$value\">\n";
}
 
function is_email($email) {
 $ret=false;
 $name="";
 $domain="";
 @list($name, $domain)=@explode("@", $email);
 if(!strstr($email, " ") && @strstr($domain, ".")) {
  $ret=true;
 }
 return $ret;
}

?>